<template>
  <div class="main flex-v">
    <div class="ioutWrap">
      <div class="balanceTop">
        <div style="position: relative;z-index: 3;">
          <!-- <go-back aa="../volunteer/indexs"></go-back> -->
          <headerBack></headerBack>
        </div>
        <div class="topHeadTitle">
          <span class="banTitle">您的专属方案已生成</span>
          <div class="watchNotes" @click="watchNotes">查看说明</div>
        </div>
      </div>
      <div class="programmeWrap">
        <scroller ref="scrollerBottom" style="top: 1.7rem;">
          <div class="programmeBox">
            <div class="new-case-box">
              <case-item @btnClick="getBalanceRecordZj" :isNew="true" :caseList="newCase"></case-item>
            </div>
            <div class="old-case-box">
              <h2 class="banTitle" v-show="caseList.length>0">历史生成方案</h2>
              <case-item  @btnClick="getBalanceRecordZj" :caseList="caseList"></case-item>
            </div>
            <div style="width: 7.5rem;height: 5.5rem;"></div>
          </div>
        </scroller>
        <div class="create-btn">
          <span @click="commonJs.gopush('stepOne')">创建新方案</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import headerBack from "~/components/headerBack";
import caseItem from "../volunteer/components/caseItem";
import { getBalanceHistoryZj,getBalanceRecordZj } from "~/api/volunteer";
import ls from "store2";
export default {
  head: {},
  components: {
    headerBack,
    caseItem
  },
  data() {
    return {
      caseList: [],
      newCase: []
    };
  },
  // created() {
  //   if (this.commonJs.GetUrlParam("pay_status") == "success") {
  //     this.$vux.toast.text("支付成功");
  //   } else if (this.commonJs.GetUrlParam("pay_status") == "failed") {
  //     this.$vux.toast.text("支付失败，请重新支付");
  //   }
  // },

  methods: {
    getBalanceRecordZj(id, tys) {
      this.$vux.loading.show();
      let that = this;
      getBalanceRecordZj(id)
        .then(res => {
          if (res.code == "0") {
            if (res.data) {
              ls.set("caseData1", res.data.balance);
              ls.set("caseData2", res.data.academy);
              ls.set("caseData3", res.data.major);
              setTimeout(() => {
                ls.set("preUrl", "../zhejiang/programrecord");
                that.$store.commit("changeUrl", "../zhejiang/programrecord");
                that.commonJs.gopush("../zhejiang/balance", tys);
              }, 50);
            }
          }
          this.$vux.loading.hide();
        })
        .catch(error => {
          this.$vux.loading.hide();
        });
    },
    hasBalanceHistory() {
      this.$vux.loading.show();
      getBalanceHistoryZj(ls.get("userType"))
        .then(res => {
          if (res.code == "0") {
            this.newCase.push(res.data[0]);
            this.caseList = res.data.filter(function(item, index) {
              return index > 0;
            });
          }
          this.$vux.loading.hide();
        })
        .catch(error => {
          this.$vux.loading.hide();
        });
    },
    goCareer() {
      let yxkData = ls.get("yxkData");
      let ure = window.location.href;
      let urls = encodeURIComponent(ure);
      let transData = {
        userArea: encodeURIComponent(ls.get("userArea")),
        userId: yxkData.userId,
        userVoId: yxkData.userVoId,
        accessToken: yxkData.accessToken,
        userType: yxkData.userType
      };
      // process.env.workUrl/h5-stu-wx/#/volunteer/indexs

      window.location.replace(
        process.env.workUrl +
          "/wx-yxk/#/univCareer" +
          "?vol_return_url=" +
          urls +
          "&volData=" +
          encodeURIComponent(JSON.stringify(transData))
      );
      // window.location.replace("http://192.168.8.202:8800/wx-yxk/#/univCareer?yxkData="+encodeURIComponent(JSON.stringify(yxkData)))
    },
    goArtificial() {
      let url = encodeURIComponent(
        process.env.workUrl + "/h5-stu-wx/#/volunteer/programrecord"
      );
      this.commonJs.checkCodeVip("dr", url, process.env.mallDrId);
    },
    watchNotes() {
      this.commonJs.gopush("notes", 2);
    }
  },

  mounted: function() {
    this.hasBalanceHistory();
  }
};
</script>

<style scoped lang="less">
.ioutWrap {
  width: 100%;
  min-height: 100vh;
  background: #fff;
  position: relative;

  .balanceTop {
    // z-index: 2;
    width: 100%;
    height: 1.7rem;

    .topBg {
      position: absolute;
      right: 0;
      top: 0;
      width: 7.5rem;
      height: auto;
    }

    .topHeadTitle {
      display: flex;
      justify-content: space-between;
      align-items: center;
      // margin-top: 0.4rem;
      margin-left: 0.3rem;
      margin-right: 0.31rem;

      .watchNotes {
        color: #222;
        font-size: 0.3rem;
        line-height: 0.44rem;
      }
    }
  }
  .banTitle {
    display: block;
    height: 0.62rem;
    font-size: 0.4rem;
    font-weight: bold;
    color: rgba(34, 34, 34, 1);
    display: block;
  }
}

.programmeWrap {
  width: 7.5rem;
  min-height: 100vh;
  height: auto;

  .pycsBox {
    display: block;
    height: 0.8rem;
    line-height: 0.8rem;
    overflow: hidden;
    background: #fff1b8;
    padding: 0 0.3rem;

    .bb1 {
      font-size: 0.26rem;
      font-weight: bold;
    }

    .ii1 {
      float: right;
      display: inline-block;
      // background: @mainColor;
      color: @mainColor;
      font-size: 0.3rem;
      height: 0.6rem;
      width: 1rem;
      text-align: center;
      line-height: 0.6rem;

      margin-top: 0.1rem;

      font-family: "PingFangSC-Semibold";
      font-weight: 600;
    }
  }

  .programmeBox {
    width: 100%;
    min-height: 15rem;
    height: auto;
    // padding: 0.3rem 0;
    box-sizing: border-box;
    position: relative;
    .new-case-box {
      width: 100%;
      height: auto;
      padding: 0 0.3rem 0.4rem 0.3rem;
      // box-sizing: border-box;
      border-bottom: 0.24rem solid rgba(247, 247, 250, 1);
    }
    .old-case-box {
      width: 100%;
      height: auto;
      padding: 0.5rem 0.3rem 0.3rem 0.3rem;
    }

    .textTitle {
      font-size: 0.5rem;
      font-weight: bold;
      color: rgba(34, 34, 34, 1);
      line-height: 0.8rem;
      display: block;
      margin-bottom: 0.6rem;
    }

    .proSmBox {
      margin-bottom: 0.2rem;
      width: 100%;
      height: 2.4rem;

      box-shadow: 0px 0px 0.2rem 0px rgba(204, 204, 204, 0.3);
      border-radius: 0.1rem;

      .left {
        padding-left: 0.3rem;
        box-sizing: border-box;

        .lefttxt1 {
          font-size: 0.4rem;

          font-weight: bold;

          line-height: 0.6rem;
          display: block;
        }

        .l1 {
          color: rgba(148, 210, 103, 1);
        }

        .l2 {
          color: rgba(254, 192, 62, 1);
        }

        .l3 {
          color: rgba(90, 178, 241, 1);
        }

        .lefttxt2 {
          display: block;
          height: auto;
          font-size: 0.24rem;

          font-weight: 500;
          color: rgba(153, 153, 153, 1);
          line-height: 0.4rem;
        }
      }

      .right {
        width: 2.43rem;
        height: 2.4rem;

        img {
          display: block;
          width: 100%;
          height: 2.4rem;
        }
      }
    }
  }
}

.create-btn {
  position: fixed;
  width: 100%;
  left: 0;
  bottom: 0;
  height: auto;
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px -0.04rem 0.1rem 0px rgba(204, 204, 204, 0.2);
  span {
    display: block;
    margin: 0.2rem auto;
    width: 6rem;
    height: 0.88rem;
    background: rgba(128, 213, 102, 1);
    border-radius: 0.44rem;
    text-align: center;
    line-height: 0.88rem;
    font-size: 0.3rem;
    font-family: PingFangSC;
    font-weight: 600;
    color: rgba(255, 255, 255, 1);
  }
}
</style>
